<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../lib/layui-v2.6.3/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <script src="../../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script src="../../../lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>

    <script src="../../../lib/jq-module/jquery.particleground.min.js" charset="utf-8"></script>


    <script src="../../../js/echarts.min.js"></script>

    <style>
        .weather {
            background: url(../images/weather_bg2.jpg) no-repeat;
            width: 250px;
            height: 88px;
            margin: 10px 2px 10px 6px;
            padding: 20px 2px 2px 65px;
        }
    </style>

</head>

<body>
    <blockquote class="layui-elem-quote layui-text">
        <!-- 天气 -->
        <div class="weather">
            <iframe width="200" scrolling="no" height="65" frameborder="0" allowtransparency="true"
                src="http://i.tianqi.com/index.php?c=code&id=12&icon=1&num=1">
            </iframe>
        </div>

    </blockquote>

    <fieldset class="table-search-fieldset">
        <legend>家居</legend>
        <div style="margin: 10px 10px 10px 10px">
            <form class="layui-form layui-form-pane" action="" id="fom1">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">家居名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="household_name" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <!-- <div class="layui-inline">
                        <label class="layui-form-label">手机号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="security_phone" autocomplete="off" class="layui-input">
                        </div>
                    </div> -->

                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                            lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>


    <table class="layui-hide  lay-data=" id="househomeTable" lay-filter="househomeTable"></table>


    <script id="picTpl">
        <img src="{{d.household_pic}}" name="household_pic" style="width:100%; height:100%;" />
    </script>
    <script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
      <button class="layui-btn layui-btn-sm" lay-event="householdadd">添加</button>
      <button class="layui-btn layui-btn-sm" lay-event="householdsdel">批量删除</button>
      <button class="layui-btn layui-btn-sm" lay-event="echarts1">家居公司折线图</button>
      <button class="layui-btn layui-btn-sm" lay-event="outexcel">导出表格</button>
      <button class="layui-btn layui-btn-sm" lay-event="escelmodel">导入模板</button>

      <button class="layui-btn layui-btn-sm" lay-event="inexcel">导入表格</button>

      <!-- <button class="layui-btn layui-btn-sm" lay-event="isAll"></button> -->
    </div>
  </script>


    <script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
  </script>

    <script src="http://ip.ws.1 26.net/ipquery"></script>
    <script type="text/javascript">
        dynamicIp(lc);//这是获取天气调用的方法 lc就是城市名称
    </script>


    <script>
        function dynamicIp(cityName) {
            $("#ctiyName").html(cityName);
            var url = encodeURI("http://wthrcdn.etouch.cn/weather_mini?city=" + cityName);
            $.get({
                url: "http://i.tianqi.com/index.php?c=code&id=12&icon=1&num=1",
                dataType: "json",
                async: false,
                success: function (data) {
                    var todayWeather = data.data.forecast[0];
                    $("#ganmao").html("穿衣指数:" + data.data.ganmao);//穿衣
                    var fengli = todayWeather.fengli;
                    $("#fengx").html("风向风力:" + todayWeather.fengxiang + fengli.substring(fengli.indexOf("T") + 3, fengli.indexOf("T") + 5));//风向
                    $("#heightwend").html("最" + todayWeather.high);//最高温
                    $("#low").html("最" + todayWeather.low);//最低温温
                    $("#wendu").html(data.data.wendu);//当前温度
                    var arr = todayWeather.date.split("日");
                    $("#date").html(arr[0] + "日<br>" + arr[1]);//当前日期
                    var type = todayWeather.type;//天气
                    if (type == "晴") {
                        changeWeather(weather[4]);
                    } else if (type == "多云") {
                        changeWeather(weather[1]);
                    } else if (type == "小雨") {
                        changeWeather(weather[2]);
                    } else if (type == "雪") {
                        changeWeather(weather[0]);
                    } else if (type == "雷阵雨") {
                        changeWeather(weather[3]);
                    }
                    $("#table_next").width($(".details").width() + 86);
                    for (var i = 1; i < data.data.forecast.length; i++) {
                        var arr = data.data.forecast[i].date.split("日");
                        var type = data.data.forecast[i].type;
                        $("#content" + i).html(arr[1]);//日期
                        if (type == "晴") {
                            document.getElementById('svgDiv' + i).className = 'sunny';
                        } else if (type == "多云") {
                            document.getElementById('svgDiv' + i).className = 'cloudy';
                        } else if (type == "小雨") {
                            document.getElementById('svgDiv' + i).className = 'rainy';
                        } else if (type == "雪") {
                            document.getElementById('svgDiv' + i).className = 'snowy';
                        } else if (type == "雷阵雨") {
                            document.getElementById('svgDiv' + i).className = 'stormy';
                        }
                    }
                }
            });

        }


        layui.use('table', function () {
            var table = layui.table,
                $ = layui.jquery,
                form = layui.form;


            // 监听搜索操作
            form.on('submit(data-search-btn)', function (data) {
                var result = JSON.stringify(data.field);

                //执行搜索重载
                table.reload('househomeTable', {
                    page: {
                        curr: 1
                    }
                    , where: {
                        // 查询条件
                        household_name: data.field.household_name,
                        serviceman_id: data.field.serviceman_id

                    }
                }, 'data');

                return false;
            });


            table.render({
                elem: '#househomeTable'
                , url: 'http:///localhost:8080/household/householdList'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , title: '智能家居'
                , totalRow: true
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'household_id', title: 'ID', fixed: 'left', unresize: true, sort: true }
                    , { field: 'household_name', title: '家居名称', edit: 'text' }
                    , { field: 'household_price', title: '价格', edit: 'text', sort: true }
                    , { field: 'household_lfdate', title: '出厂日期', sort: true }
                    , { field: 'guarantee_id', title: '保修单id', edit: 'text', sort: true }
                    , { field: 'serviceman_id', title: '维修人员id', edit: 'text', sort: true }
                    , { field: 'household_pic', width: 150, title: '家居照片', templet: '#picTpl' }
                    , {
                        field: 'household_pic', title: '家居照片', align: "center", templet: function (d) {

                            return "<span id=\"pic_" + d.household_pic + "\"><img src=\"" + base + d.picUrl + "\"  style=\"width: 40px\" lay-event=\"showPic\" ></span>";
                        }
                    },
                    , { fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150 }

                ]]
                , page: true
                , response: {
                    statusCode: 0 //重新规定成功的状态码为 200，table 组件默认为 0
                }
                , parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                    return {
                        "code": res.code, //解析接口状态
                        "msg": res.message, //解析提示文本
                        "count": res.data.count, //解析数据长度
                        "data": res.data.households //解析数据列表
                    };
                }

            });

            //头工具栏事件
            table.on('toolbar(househomeTable)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {

                        
            // 图片放大
              case 'showPic':
                {
                    layer.photos({
                        photos: '#pic_' + obj.data.id,
                        //0-6的选择，指定弹出图片动画类型，默认随机
                        anim: 5
                    });
                };
                $(window).on("resize", function () {
                    layer.full(index);
                });
                break;

                    // 添加
                    case 'householdadd':
                {
                    var index = layer.open({
                        title: '添加家居',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '80%'],
                        content: 'householdadd.html',
                        //列表重新加载
                        end: function (index) {
                            table.reload('househomeTable');
                        }
                    });
                };
                $(window).on("resize", function () {
                    layer.full(index);
                });
                break;
                    // 批量删除
                    case 'householdsdel':
                // 选中的数据
                var data = checkStatus.data;
                $.ajax({
                    type: "post",
                    url: "http://localhost:8080/household/househomesDel",
                    contentType: "application/json",
                    data: JSON.stringify(data),
                    dataType: "json",
                    success: function (res) {

                        if (res.code == 0) {
                            layer.msg('删除成功', function () {

                                table.reload('househomeTable');
                                // 关闭弹出层
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                                layer.close(index)
                                table.reload("#househomeTable")

                            })

                        } else {
                            layer.msg('删除失败', function () {

                            });
                        }
                    }

                })
                break;


                    case 'echarts1':
                {
                    var index = layer.open({
                        title: '智能家居价格折线图',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '80%'],
                        content: 'echarts1.html',
                        //列表重新加载
                        end: function (index) {
                            table.reload('househomeTable');
                        }
                    });
                };
                break;
                    case 'echarts2':
                {
                    var index = layer.open({
                        title: '添加家居',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '80%'],
                        content: 'householdadd.html',
                        //列表重新加载
                        end: function (index) {
                            table.reload('househomeTable');
                        }
                    });
                };

                break;


                    //  导出表格
                    case 'outexcel':
                {
                    debugger
                    location.href = "http://localhost:8080/household/export?" + $("#fom1").serialize();
                };
                break;

                    //  导出模板
                    case 'escelmodel':
                {
                    debugger
                    location.href = "http://localhost:8080/household/escelModel";
                };
                break;


                    //导入表格 http://localhost:8080/household/import"

                    case 'inexcel':
                {

                    var index = layer.open({
                        title: '导入表格',
                        type: 2,
                        shade: 0.2,
                        maxmin: true,
                        shadeClose: true,
                        area: ['80%', '80%'],
                        content: 'import.html',
                        //列表重新加载
                        end: function (index) {
                            table.reload('househomeTable');
                        }
                    });
                };
                break;



                    case 'LAYTABLE_TIPS':
                layer.alert('这是工具栏右侧自定义的一个图标按钮');
                break;
            };


        });

        //监听行工具事件
        table.on('tool(househomeTable)', function (obj) {
            var data = obj.data;
            console.log(obj)
            // 将读取的一行数据存储到局部存储器
            var localhostStr = localStorage.setItem("localhostStr", JSON.stringify(data));

            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();

                    $.ajax({
                        type: "post",
                        url: "http://localhost:8080/household/househomeDel",
                        contentType: "application/json",
                        data: JSON.stringify(data),
                        dataType: "json",
                        success: function (res) {

                            if (res.code == 0) {
                                layer.msg('删除成功', function () {


                                    // 关闭弹出层
                                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(iframeIndex);
                                    layer.close(index)
                                    table.reload('househomeTable');

                                })

                            } else {
                                layer.msg('删除失败', function () {

                                });
                            }
                        }

                    })



                    layer.close(index);
                });



            } else if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑家居',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'householdedit.html',
                    //列表重新加载
                    end: function (index) {
                        table.reload('househomeTable');
                    }

                });

                $(window).on("resize", function () {
                    layer.full(index);
                });

                return false;
            }
        });




        });

    </script>


</body>

</html>